package test.src.awt_swing;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class MyDialog extends JDialog {
    public MyDialog(MyFrame frame) {
        super(frame, "第一个JDialog窗体", true);
        Container container = getContentPane();
        container.add(new JLabel("这是一个对话框"));
        setBounds(120, 120, 100, 100);
    }
}

public class MyFrame extends JFrame{
    public MyFrame() {
        Container container = getContentPane();
        container.setLayout(null);
        JLabel jl = new JLabel("这是一个JFrame窗体。");
        jl.setHorizontalAlignment(SwingConstants.CENTER);
        container.add(jl);
        JButton button = new JButton("弹出对话框。");
        button.setBounds(10, 10, 100, 21);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new MyDialog(MyFrame.this).setVisible(true);
            }
        });
        container.add(button);
    }

    public static void main(String[] args) {
        new MyFrame().setVisible(true);
    }
}
